<template>
  <div class="list-container">
    <div v-if="this.workflowApplyId" class="table-panel">
      <el-steps :active="getCurrentActive(workForm.workflowNodeList,workForm.currentWorkflowNode)" :process-status="processStatus" :finish-status="finishStatus">
        <el-step
          v-for="workflowNode in workForm.workflowNodeList"
          :key="workflowNode.applyNodeId"
          :title="workflowNode.workflowNodeName">
          <template slot="description">
            <p v-if="workflowNode.examineUserName != null"><span style="color:red">审批人:</span> {{ workflowNode.examineUserName }}</p>
            <p v-if="workflowNode.examineReason != null"><span style="color:red">审批反馈:</span>{{ workflowNode.examineReason }}</p>
            <p v-if="workflowNode.examineUserName == null"><span style="color:red">节点审批人:</span>{{ workflowNode.workflowNodeUserList.map(ele =>ele.examineUserName).join() }}</p>
          </template>
        </el-step>
      </el-steps>
    </div>
  </div>
</template>

<script>
import {getTree} from "@/api/worker";
import {laborDistList,fineAndBonus} from '@/api/wage';
import workflowApi from '@/api/workflow/workFlow'
export default {
  data() {
    return {
      //页面
      companyId:localStorage.getItem("companyId"),
      totalData: 0,
      //table
      searchForm: {
        currentPage: 1,
        date:this.$route.query.date,
        endDate:null,
        pageSize: 10,
        serviceCorporationId: null,
        startDate: null,
        teamId: null,
      },
      //流程
      workForm: {
        type: '',
        applyNodeId: '',
        examineReason: '',
        workflowNodeList: [],
        currentWorkflowNode: {}
      },
      finishStatus: 'success',
      processStatus:'process',
      stepIndex:2,
      workflowApplyId:null
    };
  },
  async created(){
    this.searchForm.date=this.$route.query.date
    var workflowApplyId = this.$route.query.workflowApplyId
    if(workflowApplyId){
      this.workflowApplyId=workflowApplyId
      this.getTableListExamineWorkflowApply()
    }
  },
  methods: {
    getTableListExamineWorkflowApply() {
      console.log('workflowApplyId',this.workflowApplyId);
      workflowApi.getWorkflowApplyInfo(({applyId:this.workflowApplyId})).then(res => {
        console.log(res)
        this.workForm = res.data
        console.log(this.workForm)
      })
    },
    getCurrentActive(workflowNodeList, currentWorkflowNode) {
      let active = 0
      let processStatus = 'success'
      let that = this
      workflowNodeList.forEach(function (element, index){
        if (currentWorkflowNode !== null) {
          if (element.applyNodeId === currentWorkflowNode.applyNodeId) {
            active = index
            that.workForm.applyNodeId = element.applyNodeId
            processStatus = 'process'
          }
        } else {
          if (element.workflowNodeStatus === '3') {
            active = index
            processStatus = 'error'
          } else if (element.workflowNodeStatus === '2') {
            active = index
            processStatus = 'success'
          }
        }
      })
      this.processStatus = processStatus
      return active
    },
    convertStatus(status){
      let newStatus = "未知"
      switch (status){
        case '1': newStatus = "待审核";break;
        case '2': newStatus = "审核中";break;
        case '3': newStatus = "已审核";break;
        case '4': newStatus = "已驳回";break;
        case '5': newStatus = "已撤回";break;
      }
      return newStatus
    }
  },
};
</script>
